package com.cn.appcore.ext

import android.util.Log
import com.cn.appcore.BuildConfig

/**
 * 项目：DesignerAjDgo
 * 包名：com.cn.designerajdgo
 * 类名：log
 * 创建时间：2023/4/6 20:59
 * 创建人 @author： xiaolin
 * 描述 ：Todo...
 */

var debug= BuildConfig.DEBUG


const val TAG="xl=>"

private enum class LEVEL{
    V,D,I,W,E
}
fun String.v(tag: String = TAG) = log(LEVEL.V, tag, this)
fun String.d(tag: String = TAG) = log(LEVEL.D, tag, this)
fun String.i(tag: String = TAG) = log(LEVEL.I, tag, this)
fun String.w(tag: String = TAG) = log(LEVEL.W, tag, this)
fun String.e(tag: String = TAG) = log(LEVEL.E, tag, this)

private fun log(level: LEVEL, tag: String, message: String) {
    when (level) {
        LEVEL.V -> Log.v(tag, message)
        LEVEL.D -> Log.d(tag, message)
        LEVEL.I -> Log.i(tag, message)
        LEVEL.W -> Log.w(tag, message)
        LEVEL.E -> Log.e(tag, message)
    }
}

fun Any.loge(content: String) {
    if (debug) {
        var tag = this.javaClass.simpleName
        if (tag.isNullOrEmpty()) tag = TAG
        content.e(tag)
    }
}

fun Any.logd(content: String) {
    if (debug) {
        var tag = this.javaClass.simpleName
        if (tag.isNullOrEmpty()) tag = TAG
        content.d(tag)
    }
}

